package com.itic.ht.mem.distribution.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.itic.appbase.framework.common.constants.ResponseCode;
import com.itic.ht.mem.distribution.persistence.dao.CateDao;
import com.itic.ht.mem.distribution.persistence.model.Cate;
import com.itic.ht.mem.distribution.persistence.model.CateExample;

@Service
@Transactional
public class CateService {
	
	protected static final String SUCCESS = ResponseCode.SUCCESS.getCode();
    protected static final String FAILED = ResponseCode.SERVICE_ERROR.getCode();
	
	@Autowired
	private CateDao cateDao;

	public Cate get(String id) {
		return cateDao.selectByPrimaryKey(id);
	}

	public String edit(Cate cate) {
		int code = 0;
        String id = cate.getId();
        if (null != id ) {
            if (null == cate.getUpdateTime()) {
            	cate.setUpdateTime(new Date());
            }
            code = cateDao.updateByPrimaryKeySelective(cate);
        }
        if (1 == code) {
            return SUCCESS;
        } else if (0 == code) {
            return FAILED;
        } else {
            return FAILED;
        }
	}

	public List<Cate> list(CateExample example) {
		return cateDao.selectByExample(example);
	}

}
